package org.jsola.contract.helper;

import org.jsola.common.SafeKit;
import org.jsola.contract.dto.AppendixAddDTO;
import org.jsola.contract.dto.AppendixUpdateDTO;
import org.jsola.contract.entity.AppendixDO;
import org.jsola.contract.query.AppendixQuery;
import org.jsola.contract.service.IAppendixService;
import org.jsola.contract.vo.AppendixVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.contract.core.AbstractTest.SITE_ID;



/**
 * 合同文件
 *
 * @author JanusMix
 */
@Component
public class AppendixTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAppendixService appendixService;

    /**
     * 生成add测试数据
     * @return AppendixAddDTO
     */
    public AppendixAddDTO getAppendixAddDTO(){
        AppendixAddDTO appendixAddDTO = new AppendixAddDTO();
        appendixAddDTO.setName(getRandomValue("varchar",255));
        appendixAddDTO.setContractId(SafeKit.getLong(getRandomValue("bigint",11)));
        appendixAddDTO.setCurrentPage(SafeKit.getInteger(getRandomValue("int",11)));
        appendixAddDTO.setPath(getRandomValue("varchar",3000));
        appendixAddDTO.setPassword(getRandomValue("varchar",255));
        return appendixAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AppendixUpdateDTO
     */
    public AppendixUpdateDTO getAppendixUpdateDTO(AppendixVO appendixVO){
        return appendixService.selectDOById(appendixVO.getId(), SITE_ID).to(AppendixUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AppendixQuery
     */
    public AppendixQuery getAppendixQuery() {
        AppendixQuery appendixQuery = new AppendixQuery();
        List<AppendixDO> appendixDOList = appendixService.list(new AppendixDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(appendixDOList)) {
            AppendixDO appendixDO = appendixDOList.get(0);
            appendixQuery = appendixDO.to(AppendixQuery.class);
        }
        return appendixQuery;
    }

    /**
     * 保存示例
     * @return AppendixVO
     */
    public AppendixVO saveAppendixExample(){
        AppendixAddDTO addDTO = this.getAppendixAddDTO();
        AppendixVO appendixVO = appendixService.save(addDTO,buildTokenUser());
        return appendixVO;
    }


}

